package com.ruoyi.quartz.task;


import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.compensationManagement.domain.CompensationSalarySetting;
import com.ruoyi.system.domain.SysUserSalaryHistory;
import com.ruoyi.system.mapper.SysUserSalaryHistoryMapper;
import com.ruoyi.system.service.ISysCommonService;
import com.ruoyi.system.service.ISysUserSalaryHistoryService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 每月月底扫描保存当月所有用户薪级等级信息
 *
 * @author zy
 */
@Component("userSalaryHistoryTask")
public class UserSalaryHistoryTask {
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private ISysUserSalaryHistoryService sysUserSalaryHistoryService;
    @Autowired
    ISysCommonService sysCommonService;

    public void insertUserSalaryHistory() {
        //获取当前日期
        List<SysUser> sysUserList = sysUserService.selectAllUserList();
        for (SysUser sysUser : sysUserList) {
            if (sysUser.getUserId()!=1&&!sysUser.getDelFlag().equals("2") && !sysUser.getEmployeeType().equals("离职")) {
                CompensationSalarySetting compensationSalarySetting = sysCommonService.getCompensationSalarySettingByPayId(sysUser.getUserId());
                sysUserSalaryHistoryService.insertOrUpdateUserSalaryHistoryByUserId(compensationSalarySetting.getPayId(), sysUser.getUserId(), new Date());
            }
        }
    }
}
